package smashedapples.google.feeds
{	
	import flash.events.Event;
	
	import mx.collections.ArrayCollection;
	
	import smashedapples.core.NonVisualComponent;
	
	
	[Event(name="responseReturned",type="flash.events.Event")]
	
	[DefaultProperty("urls")]
	public class GoogleFeed extends NonVisualComponent
	{
		public function GoogleFeed()
		{
		}
		
		[ArrayElementType("String")]
		public var urls : Array;
		
		
		[Bindable]
		public var result : ArrayCollection = new ArrayCollection();
		
		
		[Bindable("responseReturned")]
		public function getEntries() : ArrayCollection
		{
			
			var array : Array = [];
			for each( var feed : GoogleFeedVO in this.result )
			{
				for each( var entry : GoogleFeedEntryVO in feed.entries)
				{
					array.push( entry );
				}
					
			}
			
			return new ArrayCollection(array);
		} 
		
		
		
		public function getFeeds():void
		{
			for each( var url : String in this.urls )
			{
				var request : GoogleFeedRequest = new GoogleFeedRequest(null,url,response);
				request.send();
			}
				
		}
		
		public function response(response:GoogleFeedResponse):void
		{
			this.result.addItem( response.feed );
			
			this.dispatchEvent( new Event("responseReturned"));
	
		}
		
		
		
	}
}